package com.boot.springBoot.juc.volaite;

import lombok.extern.slf4j.Slf4j;

/**
 * 测试volaite的内存可见性
 *
 * @author ysp
 * @since 2019/8/23 9:42
 */
@Slf4j
public class TestVolatile2 {

    public static  int number;

    public static volatile boolean flag;

    public static class myThread extends Thread{
        @Override
        public void run() {
            log.info("子线程开始运行了哦------------");
            while (!flag){
                log.info("子线程运行结束了  看看flag=={}",flag);
            }
        }
    }

    public static void main(String[] args) throws Exception{
        new myThread().start();
//        Thread.sleep(1000);
        number = 10;
        flag = true;
        log.info("------------主线程结束了哦--------------flag=={}",flag);
        Thread.sleep(3000);
    }
}
